﻿using Application.AppService.CPCAppService;
using Application.AppService.EMRAppService;
using Application.AppService.ERAppService;
using AutoMapper;
using Domain.Entity;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers.RecruitmentManagement_招聘管理_.resume_management_简历管理_
{
	public class ERController : Controller
	{
		private readonly ICPCAppService cPCAppService;
		private readonly IMapper mapper;
		private readonly IERAppService eRAppService;
		private readonly IWebHostEnvironment webHostEnvironment;

		public ERController(ICPCAppService cPCAppService, IMapper mapper,IERAppService eRAppService, IWebHostEnvironment webHostEnvironment)
		{
			this.cPCAppService = cPCAppService;
			this.mapper = mapper;
			this.eRAppService = eRAppService;
			this.webHostEnvironment = webHostEnvironment;
		}
		public IActionResult Index()
		{
			return View();
		}
		[HttpPost("GetCPCSSSAttributeKind")]
		public async Task<IActionResult> GetCPCAttributeKind(string name)
		{
			List<CPC> cpc = await cPCAppService.GetCPCAttributeKindAsync(name);
			return Json(cpc);
		}
		[HttpPost("AddER")]
		public async Task<IActionResult> AddER(ER er)
		{
			bool rs = await eRAppService.AddERAsync(er);
			return Json(rs);
		}
		[HttpPost]
		public IActionResult Upload2(IFormFileCollection file)
		{
			string name1 = "";
			foreach (var item in file)
			{
				//生成文件名
				string name = DateTime.Now.ToString("yyyyMMddHHmmssfff");
				//获取后缀名
				string ext = item.FileName.Substring(item.FileName.LastIndexOf('.'));
				//设置上传路径
				//string path = $"Uploader/{DateTime.Now.ToString("yyyy/MM/dd/")}" + name1;
				string path = $"wwwroot/images/" + name + ext;
				//Core生成文件的绝对路径
				var jpath = Path.Combine(webHostEnvironment.ContentRootPath, path);
				//创建上传文件对应的文件夹
				(new FileInfo(jpath)).Directory.Create();
				using (FileStream stream = new FileStream(jpath, FileMode.CreateNew))
				{
					item.CopyTo(stream);//图片上传
										//TempData["name"] = name + ext;//保存图片的值
				}
				name1 = name + ext;

			}
			return Content(name1);
		}
        [HttpPost]
        public IActionResult Upload3(IFormFileCollection file)
        {
            string name1 = "";
            foreach (var item in file)
            {
                //生成文件名
                string name = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                //获取后缀名
                string ext = item.FileName.Substring(item.FileName.LastIndexOf('.'));
                //设置上传路径
                //string path = $"Uploader/{DateTime.Now.ToString("yyyy/MM/dd/")}" + name1;
                string path = $"wwwroot/WenJian/" + name + ext;
                //Core生成文件的绝对路径
                var jpath = Path.Combine(webHostEnvironment.ContentRootPath, path);
                //创建上传文件对应的文件夹
                (new FileInfo(jpath)).Directory.Create();
                using (FileStream stream = new FileStream(jpath, FileMode.CreateNew))
                {
                    item.CopyTo(stream);//图片上传
                                        //TempData["name"] = name + ext;//保存图片的值
                }
                name1 = name + ext;

            }
            return Content(name1);
        }
    }
}
